home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************
- * ConstructMyAddress.c
- *
- * 8/8/94
- * By: Scott Kuechle
- * Apple Developer Technical Support
- *
- * Written in MPW 3.3.1 C
- * Compiles with 68K interfaces
- *
- * Description:
- *
- * Creates an AOCE packedDSSpec structure representing the address of the mailbox
- * of the machine that it is running on. This could then, for example, be passed to
- * SMPResolveToRecipient to create a mail address for the given machine.
- *
- *****************************************************************/
-
-
- #include <AppleTalk.h>
- #include <OCE.h>
- #include <OCEMessaging.h>
- #include <errors.h>
- #include <TextUtils.h>
- #include <Resources.h>
-
- OSErr ConstructMyAddress(EntityPtr entityPtr,
- PackedDSSpecPtr *packedDSSpecPtr,
- OCERecipient *recipient);
- OSErr BuildOurEntity(EntityPtr entityPtr);
- OSErr GetOurZoneName(StringPtr zonePtr);
-
- /* globals */
- #define gThisZone "\p*"
-
- /*****************************************************************
- * ConstructMyAddress
- *
- * Build an NBP EntityName structure representing this machine and then use that to
- * construct a packedDSSpec (or OCERecipient ) structure.
- *****************************************************************/
-
- OSErr ConstructMyAddress(EntityPtr entityPtr,
- PackedDSSpecPtr *packedDSSpecPtr,
- OCERecipient *recipient)
- {
- OSErr err;
- RString32 *recordName;
- unsigned short packedSpecSize;
- RecordIDPtr ridPtr;
-
-
- err = BuildOurEntity(entityPtr);
- if (err == noErr)
- {
- ridPtr = (RecordIDPtr)NewPtr(sizeof(RecordID));
- err = MemError();
- if (err == noErr)
- {
- ridPtr->rli = NULL;
- recipient->entitySpecifier = ridPtr;
- OCESetCreationIDtoNull(&ridPtr->local.cid);
- ridPtr->local.recordType = OCEGetIndRecordType(kUserRecTypeNum);
- recordName = (RString32 *) NewPtr(sizeof(RString32));
- err = MemError();
- if (err == noErr)
- {
- OCEPToRString(&entityPtr->objStr,
- smRoman,
- (RStringPtr)recordName,
- kRString32Size);
- ridPtr->local.recordName = (RStringPtr)recordName;
-
- recipient->extensionType = kOCEalanXtn;
- /* extension is the entity name */
- recipient->extensionSize = (entityPtr->objStr[0] + 1) +
- (entityPtr->typeStr[0] + 1) +
- (entityPtr->zoneStr[0] + 1);
- recipient->extensionValue = (Ptr)entityPtr;
-
- /* construct a packedDSSpec */
- packedSpecSize = OCEPackedDSSpecSize(recipient);
- *packedDSSpecPtr = (PackedDSSpecPtr)NewPtr(packedSpecSize);
- err = MemError();
- if (err == noErr)
- err = OCEPackDSSpec(recipient, *packedDSSpecPtr, packedSpecSize);
- }
- }
- }
- return (err);
- }
-
- /*****************************************************************
- * BuildOurEntity
- *
- * Builds an AppleTalk NBP EntityName structure representing this machine.
- *****************************************************************/
-
- OSErr BuildOurEntity(EntityPtr entityPtr)
- {
- StringHandle userName;
- OSErr err;
- short resError;
-
-
- err = GetOurZoneName(&entityPtr->zoneStr[0]);
- if (err == noErr)
- {
- BlockMove(kIPMWSReceiverNBPType,
- &entityPtr->typeStr[0],
- kIPMWSReceiverNBPType[0]+1);
- /* get flagship name */
- userName = GetString(-16413);
- if (userName != NULL)
- BlockMove(*userName,
- &entityPtr->objStr[0],
- *userName[0]+1);
- else
- {
- resError = ResError();
- if (resError == noErr)
- return (resNotFound);
- else
- return (resError);
- }
- }
-
- return (err);
- }
-
- /*****************************************************************
- * GetOurZoneName
- *
- * Calls the AppleTalk PGetAppleTalkInfo call to retrieve the zone name for this
- * machine.
- *****************************************************************/
- OSErr GetOurZoneName(StringPtr zonePtr)
- {
- MPPParamBlock pb;
- OSErr err;
-
- pb.GAIINFO.version = 1; /* assume Phase 2 drivers */
- pb.GAIINFO.LAlength = 0;
- pb.GAIINFO.linkAddr = NULL;
- pb.GAIINFO.zoneName = zonePtr;
-
- err = PGetAppleTalkInfo(&pb, false);
- if (err == noErr)
- { /* is there no zone name? */
- if ((*(unsigned char *)(*zonePtr)) == 0)
- /* specify "this" zone */
- BlockMove(gThisZone,
- zonePtr,
- gThisZone[0]+1);
- }
- return (err);
- }
-